import { Descriptions, Form } from 'antd';
import React, { useState, useRef } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { queryDailyReports } from './service';
import { connect } from 'dva';
import {formatPrice} from '@/utils/utils';
import db from '@/utils/localstorage';
const typeMap={
  1:'首次绑卡',
  2:'开卡',
  3:'临时停卡',
  4:'退卡',
  5:'再次绑卡',
}
const DayReport = () => {
  const [totalInfo,setTotalInfo] = useState({});
  const [dictTypeList, setDictTypeList] = useState(db.get("dictTypeList")['payment_method']);
  const [columns, setColumns] = useState([
    {
      title: '员工名称',
      dataIndex: 'userName',
    },
    {
      title: '会员名称',
      dataIndex: 'memberName',
    },
    {
      title: '金额(+/-)',
      dataIndex: 'sumOfMoney',
      hideInSearch: true,
    },
    {
      title: '消费时间',
      dataIndex: 'countDate',
      valueType: 'date',
    },
    {
      title: '支付类型',
      dataIndex: 'paymentType',
      hideInSearch: true,
      render:(text)=>{
        return dictTypeList?.filter(item=>(item.value === `${text}` || item.value ===text))?.[0].label??''
      }
    },
    {
      title: '事由',
      dataIndex: 'type',
      hideInSearch: true,
      render:(text)=>{
        return typeMap[text];
      }
    },
    {
      title: '备注',
      dataIndex: 'bz',
      hideInSearch: true,
    },
  ]);
  const [form] = Form.useForm();
  const actionRef = useRef();

  return (
    <PageHeaderWrapper content={<Descriptions>
      <Descriptions.Item label="今日实收">{formatPrice(totalInfo.netReceipts??0)}元</Descriptions.Item>
      <Descriptions.Item label="今日进项">{formatPrice(totalInfo.income??0)}元</Descriptions.Item>
      <Descriptions.Item label="今日支出">{formatPrice(totalInfo.expenditure??0)}元</Descriptions.Item>
    </Descriptions>}>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        params={{
        }}
        pagination={false}
        request={params => {
          let _params = {
            pageNum: params.current,
            ...params,
          }
          delete _params.current
          return queryDailyReports(_params)
        }}
        postData={result => {
          setTotalInfo(result);
          return result.detailedVO;
        }}
        columns={columns}
        rowSelection={{}}
      />
    </PageHeaderWrapper>
  );
};

export default connect(({ loading, cubeDayReport }) => ({
  shopList: cubeDayReport.shopList
}))(DayReport);